import requests
import time


class HandTicket(object):

    def __init__(self, url, method):
        self.url = url
        self.method = method
        self.session = requests.session()

    def hand_request(self,url,method):
        try:
            if method == "GET":
                response = self.session.get(url=url,method=method)
            elif method == "POST":
                response = self.session.post(url=url,method=method)
        except:
            self.session.cookies.clear()
            first_url = "https://www.lagou.com/jobs/list_python?city=%s&cl=false&fromSearch=true&labelWords=&suginput="
            self.hand_request(url=first_url,method="GET")
            time.sleep(20)
        response.encoding("utf-8")
        if '频繁' in response.text:
            print(response.text)
            self.session.clear()
            first_url = "https://www.lagou.com/jobs/list_python?city=%s&cl=false&fromSearch=true&labelWords=&suginput="
            self.hand_request(url=first_url,method="GET")
            time.sleep(20)
        return response.text


if __name__ == '__main__':
    handTicket = HandTicket
    handTicket.hand_request(url="https://baidu.com/index",method="GET")